
package br.siseventos.view.conversores;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class ConversorDataHora extends BaseConverter{
    // <editor-fold desc="Campos">

    private DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm");
    // </editor-fold>
    // <editor-fold desc="Construtor">

    public ConversorDataHora() {
    }

    // </editor-fold>
    // <editor-fold desc="Sobrescritas">
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        DateTime dateTime = DateTime.parse(value, dateTimeFormatter);
        return dateTime.toDate();
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return dateTimeFormatter.print(new DateTime(value));
    }
    // </editor-fold>
}